package com.test.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

/**
 * 1.Runnable没有返回值，Callable有返回值
 * 2.Runnable实现的方法不会抛出异常，Callable实现的方法会抛出异常
 * 3.方法不一样，一个run。一个call
 */
class MyThread implements Runnable{

    @Override
    public void run() {

    }
}

class Mythread2 implements Callable<Integer>{

    @Override
    public Integer call() throws Exception {
        System.out.println("=============comin in ");
        TimeUnit.SECONDS.sleep(2);
        return 1024;
    }
}
public class CallableDemo {
    public static void main(String[] args) throws Exception{
        FutureTask<Integer> futureTask = new FutureTask(new Mythread2());//实现 RunnableFuture接口，RunnableFuture接口继承自Runnable接口
       // FutureTask futureTask1 = new FutureTask(new MyThread(),1);
        new Thread(futureTask,"AA").start();
        new Thread(futureTask,"BB").start();
        int ressult10 = 100 ;
        while (!futureTask.isDone()){

        }
        int result = futureTask.get();
        System.out.println(ressult10+result);
    }
}
